package com.kinglone.back.userPKRole.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kinglone.back.user.model.User;
import com.kinglone.back.userPKRole.dao.UserPKRoleMapper;
import com.kinglone.back.userPKRole.service.UserPKRoleService;

@Service("userPKRoleService")
public class UserPKRoleServiceImpl implements UserPKRoleService {

	@Autowired
	private UserPKRoleMapper userPKRoleDao;

	@Override
	public void unBindUser(String userIds, String roleId) {
		try {
			String[] arrIds = userIds.split(",");
			for(String userId : arrIds){
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("userId", userId);
				params.put("roleId", roleId);
				userPKRoleDao.removeUserByUserIdAndRoleId(params);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}

	@Override
	public List<User> findUnBindUsers(String roleId) {
		return userPKRoleDao.findUnBindUsers(roleId);
	}

	@Override
	public void bindUser(String userIds, String roleId) {
		try {
			String[] arrIds = userIds.split(",");
			for(String userId : arrIds){
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("userId", userId);
				params.put("roleId", roleId);
				userPKRoleDao.bindUser(params);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
